package validate

import (
	"Godzilla/enum/fileds"
	"reflect"
)

// SortValidate 检验sort字段正序还是倒序
func SortValidate(sort string) bool {
	var validFiled = []string{fileds.ASC, fileds.DESC}
	for _, v := range validFiled{
		if v == sort {
			return true
		}
	}
	return false
}

// SortFileValidate 检验字段是否在结构体中
func SortFileValidate(filed string, model interface{}) bool {
	ele := reflect.TypeOf(model).Elem()
	for i := 0; i< ele.NumField(); i++ {
		if ele.Field(i).Tag.Get("json") == filed {
			return true
		}
	}
	return false
}

// StatusFileValidate 判断status是否等于1 或者 -1
func StatusFileValidate(filed int8) bool {
	var validFiled = []int8{fileds.Enable, fileds.Disable}
	for _, v := range validFiled {
		if v == filed {
			return true
		}
	}
	return false
}
